<#include "include/head.ftl">
<#assign isCbd = false>
<#assign idJavaType="long">
<#list table.columnList as column>
    <#if column.columnName?lower_case=='creator'>
        <#assign isCbd = true>
    </#if>
    <#if column.columnName?lower_case=='id'>
        <#assign idJavaType = column.columnSimpleClassName>
    </#if>
</#list>

package ${NamespaceDomain};

import java.io.Serializable;
import java.util.*;
import ${NamespaceProject}.annotation.*;

/**
 * 《${tableLabel}》 实体
 * @author ${copyright.author}
 *
 */
@Table(value="${table.tableName}")
public class ${Po}Entity implements Serializable {
	private static final long serialVersionUID = 1L;
	
	<#list table.columnList as column>
	<#if (column.primaryKey && column.columnName?lower_case='id')>
	@PK(value="${column.fieldName}")
	<#else>
	@Column(value="${column.fieldName}")
	</#if>
	private ${column.columnSimpleClassName} ${column.columnName?uncap_first}; //${column.columnLabel}
	
	</#list>
	private Map<${Po}Enum,List> columnValueListMap = new HashMap<${Po}Enum,List>();  //字段集合Map
	
	<#if tableSplit=true>
	private Integer tableId ;  //表Id
	</#if>
	
    
	/**
	 *默认空构造函数
	 */
	public ${Po}Entity() {
		super();
	}
	 
	<#list table.columnList as column>
	/**
	 * @return ${column.fieldName} ${column.columnLabel}
	 */
	public ${column.columnSimpleClassName} get${column.columnName?cap_first}(){
		return this.${column.columnName?uncap_first};
	}
	/**
	 * @param ${column.fieldName} ${column.columnLabel}
	 */
	public void set${column.columnName?cap_first}(${column.columnSimpleClassName} ${column.columnName?uncap_first}){
		this.${column.columnName?uncap_first} = ${column.columnName?uncap_first};
	}
	
	/**
	 * @return List<${column.columnSimpleClassName}> 【${column.columnLabel}】集合
	 */
	public List<${column.columnSimpleClassName}> get${column.columnName?cap_first}List(){
	    if(columnValueListMap!=null&&!columnValueListMap.isEmpty()){
	        List<${column.columnSimpleClassName}> ${column.columnName?cap_first}List = (List<${column.columnSimpleClassName}>)this.columnValueListMap.get(${Po}Enum.${column.columnName});
	        return ${column.columnName?cap_first}List;
	    }
		return null;
	}
	/**
	 * @param ${column.fieldName} ${column.columnLabel} 添加集合
	 */
	public void add${column.columnName?cap_first}List(${column.columnSimpleClassName} ${column.columnName?uncap_first}){
	    if(columnValueListMap!=null){
	        List<${column.columnSimpleClassName}> ${column.columnName?cap_first}List = this.columnValueListMap.get(${Po}Enum.${column.columnName});
	        if(${column.columnName?cap_first}List==null){
	            ${column.columnName?cap_first}List = new ArrayList<${column.columnSimpleClassName}>();
	            this.columnValueListMap.put(${Po}Enum.${column.columnName},${column.columnName?cap_first}List);
	        }
	        ${column.columnName?cap_first}List.add(${column.columnName?uncap_first});
	    }
	}
	/**
	 * @param ${column.fieldName} ${column.columnLabel} 添加所有集合
	 */
	public void add${column.columnName?cap_first}AllList(List<${column.columnSimpleClassName}> ${column.columnName?uncap_first}ParamList){
	    if(columnValueListMap!=null){
	        List<${column.columnSimpleClassName}> ${column.columnName?cap_first}List = this.columnValueListMap.get(${Po}Enum.${column.columnName});
	        if(${column.columnName?cap_first}List==null){
	            ${column.columnName?cap_first}List = new ArrayList<${column.columnSimpleClassName}>();
	            this.columnValueListMap.put(${Po}Enum.${column.columnName},${column.columnName?cap_first}List);
	        }
	        ${column.columnName?cap_first}List.addAll(${column.columnName?uncap_first}ParamList);
	    }
	}
	/**
	 * @param 清空${column.fieldName} ${column.columnLabel} 集合
	 */
	public void clear${column.columnName?cap_first}List(){
	    if(columnValueListMap!=null){
	        List<${column.columnSimpleClassName}> ${column.columnName?cap_first}List = this.columnValueListMap.get(${Po}Enum.${column.columnName});
	        if(${column.columnName?cap_first}List!=null&&!${column.columnName?cap_first}List.isEmpty()){
	            ${column.columnName?cap_first}List.clear();
	        }
	    }
	}
	</#list>
	
	<#if tableSplit=true>
	public void setTableId(Integer tableId) {
		this.tableId = tableId;
	}
	
	public Integer getTableId() {
		return this.tableId;
	}
	
	public String getTableName() {
		return "${table.tableName}"+"_"+this.tableId;
	}
	
	public static String getDefaultTableName() {
		return "${table.tableName}";
	}
	<#else>
    public String getTableName() {
	   return "${table.tableName}";
	}
	</#if>
	
	@Override
	public String toString(){
		StringBuilder builder = new StringBuilder();
		builder.append("${Po} [")
		<#list table.columnList as column>
		<#if column_index==0>
		.append("${column.columnName}=").append(this.get${column.columnName?cap_first}())
		<#else>
		.append(",${column.columnName}=").append(this.get${column.columnName?cap_first}())
		</#if>
		.append(",${column.columnName}List=").append(this.get${column.columnName?cap_first}List())
		</#list>
		<#if tableSplit=true>
		.append(",tableId=").append(this.getTableId())
		</#if>
		.append("]");
		return builder.toString();
	}
	
	/**
	** 获取查询数据库的所有字段
	**/
	public static String getAllSelectFiled(String filedPrixf){
	    StringBuffer filedSql = new StringBuffer();
	    for(${Po}Enum enumEntity:${Po}Enum.values()){
	        if(filedPrixf==null||filedPrixf.length()==0){
	            filedSql.append(enumEntity.get()).append(",");
	        }else{
	           filedSql.append(filedPrixf).append(".").append(enumEntity.get()).append(",");
	        }
		}
		return filedSql.substring(0, filedSql.length()-1);
	}
	
	public static enum ${Po}Enum{
		<#list table.columnList as column>
		<#if !column_has_next>
		${column.columnName}("${column.fieldName}","${column.columnLabel}");
		<#else>
		${column.columnName}("${column.fieldName}","${column.columnLabel}"),
		</#if>
		</#list>
		
		private String fieldName;
		private String remark;
		
		${Po}Enum(String fieldName,String remark){
			this.fieldName = fieldName;
			this.remark = remark;
		}
		
		public String get(){
			return this.fieldName;
		}
		
		public String getRemark(){
			return this.remark;
		}
	}
}
